#include <iostream>

using namespace std;

/*
 * 左移运算符重载
 */

class Person{
public:

    // 成员函数重载左移运算符
    ostream & operator<<(ostream & cout) {  // 本质调用p.operator<<(cout)
        cout << "p1.p_a= " << this->p_a << ", p1.p_b= " << this->p_b;
        return cout;
    }

    Person(int a, int b){
        p_a = a;
        p_b = b;
    }
    int p_a;
    int p_b;
};

// 全局函数重载左移运算符   返回ostream & 为链式编程思想, 传参cout为引用是因为对象只能有一个
//ostream & operator<<(ostream &cout, Person p){  // 本质调用 operator<<(cout, p)
//    cout << "p.p_a= " << p.p_a << ", p.p_b= " << p.p_b;
//    return cout;
//}

void test(){
    Person p(10, 20);
    // 全局函数重载
//    cout << p << endl;

    //成员函数重载
    p << cout << endl;
}

int main() {
    test();

    return 0;
}
